#include "SQLTableSampling.h"
#include "../../visitor/SQLASTVisitor.h"

SQLTableSampling::SQLTableSampling() {}

SQLObject_ptr SQLTableSampling::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLTableSampling>(new SQLTableSampling());
  std::shared_ptr<SQLTableSampling> x = std::dynamic_pointer_cast<SQLTableSampling>(clone_tmp);

  // SQLTableSampling *x = new SQLTableSampling();

  if (bucket != NULL)
  {
    x->setBucket(bucket);
  }

  if (outOf != NULL)
  {
    x->setOutOf(outOf);
  }

  if (on != NULL)
  {
    x->setOn(on);
  }

  if (percent != NULL)
  {
    x->setPercent(percent);
  }

  if (rows != NULL)
  {
    x->setRows(rows);
  }

  if (byteLength != NULL)
  {
    x->setByteLength(byteLength);
  }

  x->bernoulli = bernoulli;
  x->system = system;
  return x;
}

SQLExpr_ptr SQLTableSampling::getBucket()
{
  return bucket;
}

void SQLTableSampling::setBucket(SQLExpr_ptr x)
{
  if (x != NULL)
  {
    // x->setParent(this);
  }
  this->bucket = x;
}

SQLExpr_ptr SQLTableSampling::getOutOf()
{
  return outOf;
}

void SQLTableSampling::setOutOf(SQLExpr_ptr x)
{
  if (x != NULL)
  {
    // x->setParent(this);
  }
  this->outOf = x;
}

SQLExpr_ptr SQLTableSampling::getOn()
{
  return on;
}

void SQLTableSampling::setOn(SQLExpr_ptr x)
{
  if (x != NULL)
  {
    // x->setParent(this);
  }
  this->on = x;
}

SQLExpr_ptr SQLTableSampling::getPercent()
{
  return percent;
}

void SQLTableSampling::setPercent(SQLExpr_ptr x)
{
  if (x != NULL)
  {
    // x->setParent(this);
  }
  this->percent = x;
}

void SQLTableSampling::accept0(SQLASTVisitor_ptr v)
{
  if (v->visit(SharedObject(SQLTableSampling)))
  {
    acceptChild(v, bucket);
    acceptChild(v, outOf);
    acceptChild(v, on);
    acceptChild(v, percent);
    acceptChild(v, byteLength);
  }
  v->endVisit(SharedObject(SQLTableSampling));
}

BOOL_ptr SQLTableSampling::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (bucket == expr)
  {
    setBucket(target);
    return BOOL::TRUE;
  }

  if (outOf == expr)
  {
    setOutOf(target);
    return BOOL::TRUE;
  }

  if (on == expr)
  {
    setOn(target);
    return BOOL::TRUE;
  }

  if (percent == expr)
  {
    setPercent(target);
    return BOOL::TRUE;
  }

  if (byteLength == expr)
  {
    setByteLength(target);
    return BOOL::TRUE;
  }
  return BOOL::FALSE;
}

SQLExpr_ptr SQLTableSampling::getByteLength()
{
  return byteLength;
}

void SQLTableSampling::setByteLength(SQLExpr_ptr x)
{
  if (x != NULL)
  {
    // x->setParent(this);
  }
  this->byteLength = x;
}

SQLExpr_ptr SQLTableSampling::getRows()
{
  return rows;
}

void SQLTableSampling::setRows(SQLExpr_ptr x)
{
  if (x != NULL)
  {
    // x->setParent(this);
  }
  this->rows = x;
}

BOOL_ptr SQLTableSampling::isBernoulli()
{
  return bernoulli;
}

void SQLTableSampling::setBernoulli(BOOL_ptr bernoulli)
{
  this->bernoulli = bernoulli;
}

BOOL_ptr SQLTableSampling::isSystem()
{
  return system;
}

void SQLTableSampling::setSystem(BOOL_ptr system)
{
  this->system = system;
}
